package com.jian.android.autojipai.app.helper;

import android.content.Context;
import android.text.TextUtils;
import java.io.File;
import java.io.FileOutputStream;

public class FileTool {

    public static class FileToolInstance {
        private static final FileTool instance = new FileTool();

        private FileToolInstance() {
        }
    }

    private FileTool() {
    }

    public static FileTool getInstance() {
        return FileToolInstance.instance;
    }

    public void createFile(Context context, String str) {
        try {
            File file = new File(context.getExternalFilesDir(null) + File.separator + str);
            if (file.exists()) {
                return;
            }
            file.createNewFile();
        } catch (Exception unused) {
        }
    }

    public void saveException(Context context, String str, String str2) {
        if (context == null || TextUtils.isEmpty(str)) {
            return;
        }
        try {
            File file = new File(context.getExternalFilesDir(null) + File.separator + str2);
            if (!file.exists()) {
                file.createNewFile();
            }
            FileOutputStream fileOutputStream = new FileOutputStream(file, true);
            try {
                fileOutputStream.write(str.getBytes());
                fileOutputStream.write("\n".getBytes());
                fileOutputStream.flush();
                fileOutputStream.close();
            } catch (Throwable e) {
                fileOutputStream.close();
                e.printStackTrace();
            }
        } catch (Throwable e4) {
            e4.printStackTrace();
        }
    }
}
